package com.example.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.io.XMLWriter;

public class XMLUtil {
	public static void create(String filepath,Document doc){
		File file=new File(filepath);
		if(!file.exists()){
			file.mkdirs();
		}
		try {
			  XMLWriter	writer = new XMLWriter(new FileWriter(file));
			  writer.write(doc);
	          writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	        
	}
	public static void create(String filepath,String xml){
		try {
			Document doc=DocumentHelper.parseText(xml);
			File file=new File(filepath);
			if(!file.exists()){
				file.mkdirs();
			}
			  XMLWriter	writer = new XMLWriter(new FileWriter(file));
			  writer.write(doc);
	          writer.close();
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		
	}
	

}
